 /**
 * @file tkl_zcl_scene.h
 * @brief Common process - scene
 * @version 1.0.0
 * @date 2021-05-13
 *
 * @copyright Copyright 2021-2022 Tuya Inc. All Rights Reserved.
 *
 */

#ifndef __TKL_ZCL_SCENE_H__
#define __TKL_ZCL_SCENE_H__


#ifdef __cplusplus
    extern "C" {
#endif

#include "tuya_cloud_types.h"


/*
 *  scenes max buffer size
 */
#define SCENES_MAX_SCENE_DATA_LEN   64

/*
 *  scene data type
 */
typedef enum {
    TKL_SCENE_DATA_TYPE_EXT_SERVER = 0, ///< scene data with extension field, save scene data in sdk
    TKL_SCENE_DATA_TYPE_YOURSELF = 1,   ///< scene data without extension field, save scene data not in sdk
    TKL_SCENE_DATA_TYPE_ZIGBEE = 2,     ///< not used 
} TKL_SCENE_TYPE_T;

/*
 *  zigbee scene structure
 */
typedef struct {
    UINT8_T           is_active;    ///< scene table entry is active
    TKL_SCENE_TYPE_T  type;         ///< scene type
    UINT8_T           ep_id;        ///< endpoint id of scene
    UINT8_T           scene_id;     ///< scene id
    UINT16_T          group_id;     ///< group id
    UINT16_T    trans_time;         ///< seconds required for the device to change from its current state to the requested scene
    UINT8_T     trans_time100ms;    ///< check if this causes any problems
    UINT8_T     data_len;           ///< scene data len
    UINT8_T     data[SCENES_MAX_SCENE_DATA_LEN];    ///< pointer to scene data
} TKL_SCENE_T;

/*
 *  zigbee mini scene structure
 */
typedef struct {
    UINT8_T     ep_id;          ///< endpoint id of scene
    UINT8_T     scene_id;       ///< scene id
    UINT16_T    group_id;       ///< group id
    UINT16_T    trans_time;     ///< seconds required for the device to change from its current state to the requested scene
    UINT8_T     trans_time100ms;///< check if this causes any problems
} TKL_MINI_SCENE_T;


typedef OPERATE_RET (*TKL_SAVE_SCENE_PRE_CB)(UINT8_T ep_id, UINT8_T scene_id, UINT16_T group_id);
typedef OPERATE_RET (*TKL_SAVE_SCENE_CB)(TKL_SCENE_T *entry);
typedef OPERATE_RET (*TKL_VIEW_SCENE_CB)(TKL_SCENE_T *entry);
typedef OPERATE_RET (*TKL_REMOVE_SCENE_CB)(UINT8_T ep_id, UINT8_T scene_id, UINT16_T group_id);
typedef OPERATE_RET (*TKL_REMOVE_ALL_SCENE_CB)(UINT8_T ep_id, UINT16_T group_id);
typedef OPERATE_RET (*TKL_RECALL_SCENE_CB)(UINT8_T ep_id, UINT8_T scene_id, UINT16_T group_id, UINT16_T time100ms);

/*
 *  zigbee scene callback collection
 */
typedef struct {
    TKL_SAVE_SCENE_PRE_CB   save_scene_pre_cb;      ///< add or store scene pre-callback 
    TKL_SAVE_SCENE_CB       save_scene_cb;          ///< add and store callback
    TKL_VIEW_SCENE_CB       view_scene_cb;          ///< view scene callback
    TKL_RECALL_SCENE_CB     recall_scene_cb;        ///< recall scene callback
    TKL_REMOVE_SCENE_CB     remove_scene_cb;        ///< remove scene callback
    TKL_REMOVE_ALL_SCENE_CB remove_all_scene_cb;    ///< remove all scene callback
} TKL_SCENE_CB_T;


/**
 * @brief get scenes table size
 *
 * @param[in]   none
 * @return  scene table size
 */
UINT8_T tkl_zg_scene_size_get(VOID_T);

/**
 * @brief find scenes on endpoint
 *
 * @param[in]   ep_id:    endpoint
 * @param[in]   scene_id: scene id
 * @param[in]   group_id: group id
 * @return  TRUE/ FALSE
 */
BOOL_T tkl_zg_find_scene(UINT8_T ep_id, UINT8_T scene_id, UINT16_T group_id);

/**
 * @brief clear all scenes
 *
 * @param[in]   none
 * @return  none
 */
VOID_T tkl_zg_clear_all_scene(VOID_T);

/**
 * @brief tuya scene table recovery to native SDK scene table
 *
 * @param[in]   scene_list: tuya scenes table
 * @param[in]   sums:       tuya scenes table number
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */
OPERATE_RET tkl_zg_scene_recovery(TKL_MINI_SCENE_T *scene_list, UINT8_T sums);

/**
 * @brief scenes callback register 
 *
 * @param[in]   scene_cb:    scene callback collection
 * @return OPRT_OK on success. Others on error, please refer to tuya_error_code.h
 */
OPERATE_RET tkl_zg_scene_cb_register(TKL_SCENE_CB_T *scene_cb);


#ifdef __cplusplus
}
#endif

#endif
